package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.shuihuyezicard.ShuiHuYeZiCardMgr;

import java.util.ArrayList;
import java.util.List;

public class YeZiCardRecyleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = ShuiHuYeZiCardMgr.getActivityInfo();
        if (activityInfo != null) {
            long recycleEndTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
            addMarkItem(activityInfo, eItemId.SHUIHUYEZICARD_INVITATION_ITEM.getValue(), eItemId.SHUIHUYEZICARD_INTEGRAL_ITEM.getValue(), 0, recycleEndTime);
            long recycleEndShowTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
            ActivityItemRecycleMgr.addRecycleItemData(eItemId.SHUIHUYEZICARD_DISPERSE_GOLD_ITEM.getValue(), activityType, 1, recycleEndShowTime, new ArrayList<>());
            addMarkItem(activityInfo, eItemId.SHUIHUYEZICARD_GOLDEN_LEAF_ITEM.getValue(), eItemId.SHUIHUYEZICARD_INTEGRAL_ITEM.getValue(), 0, recycleEndShowTime);

        }
    }

    private void addMarkItem(ActivityInfo activityInfo, int itemId, int scoreItemId, int index, long recycleTime) {
        //标记道具
        List<String> paramList = new ArrayList<>();
        paramList.add(String.valueOf(itemId));
        paramList.add(String.valueOf(scoreItemId));
        paramList.add(String.valueOf(index));
        paramList.add(activityInfo.getActivityName());
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 2, recycleTime, paramList);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.ShuiHuYeZiCardActivity.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int recycleType = data.getRecycleType();
        if (recycleType == 1) {
            int itemId = data.getItemId();
            UserBagItem bagItem = getUserBagItem(userId, itemId);
            removeItem(bagItem);
        } else if (recycleType == 2) {
            item2Score(userId, data);
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
